package com.mall.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mall.entity.GoodsVisit;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 商品访问历史表 Mapper 接口
 * </p>
 *
 * @author ShouPeng
 * @since 2024-01-19
 */
@Mapper
@Repository
public interface GoodsVisitMapper extends BaseMapper<GoodsVisit> {

    /**
     * 查询商品访问历史
     * @param userId
     * @return
     */
    @Select("select mgv.*,goods_price,goods_cover,goods_name,goods_desc from mall_goods_visit mgv left join book_mall.mall_goods mg on mgv.goods_id = mg.goods_id " +
            "where mgv.user_id = #{userId} and mgv.is_delete = 0 order by visit_date DESC")
    List<GoodsVisit> queryGoodsVisitRecord(String userId);

    @Update("UPDATE mall_goods_visit SET is_delete = 1 WHERE visit_id = #{visitId}")
    int deleteByVisitId(String visitId);

    @Update("UPDATE mall_goods_visit SET is_delete = 1 WHERE user_id = #{userId}")
    int clearGoodsHistory(String userId);
}
